<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改医院')" />
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css"/>
    <th:block th:include="include :: jquery-smartwizard-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-select-css"/>
    <th:block th:include="include :: summernote-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-japanNews-edit" th:object="${japanNews}" style="padding: 20px">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">文章标题：</label>
                    <div class="col-sm-10">
                        <input name="name" th:field="*{name}" class="form-control" type="text">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">关键词：</label>
                    <div class="col-sm-10">
                        <input name="keywords" th:field="*{keywords}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">作者来源：</label>
                    <div class="col-sm-10">
                        <input name="authorSource" th:field="*{authorSource}" class="form-control" type="text">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">类型</label>
                    <div class="col-sm-10">
                        <select name="type" class="form-control" id="type"
                                th:with="type=${@dict.getType('japan_news_type')}" lay-filter="type"
                                th:field="*{type}"
                                data-placeholder="请选择类型">
                            <option value="">请选择类型</option>
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                    th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-6">
                    <label class="col-sm-2 control-label">标签</label>
                    <div class="col-sm-10">
                        <label class="radio-box"> <input type="radio"  name="label" th:field="*{label}" value="1" /> 头条 </label>
                        <label class="radio-box"> <input type="radio"  name="label" th:field="*{label}" value="2" /> 顶置 </label>
                        <label class="radio-box"> <input type="radio"  name="label" th:field="*{label}" value="3" /> 推荐 </label>
                        <label class="radio-box"> <input type="radio"  name="label" th:field="*{label}" value="4" /> 特推 </label>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">描述：</label>
                <div class="col-sm-11">
                    <textarea name="description" th:field="*{description}" class="form-control" type="text"></textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">文章内容：</label>
                <div class="col-sm-11">
                    <input type="hidden" class="form-control" th:field="*{content}">
                    <div class="summernote" id="content"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">新闻图片：</label>
                <div class="col-sm-11">
                    <input type="hidden" th:value="*{newImgPath}" name="newImgPath">
                    <div class="file-loading">
                        <input class="form-control file-upload"  id="newImgPath" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">温馨提示：</label>
                <div class="col-sm-11">
                    <textarea name="warmPrompt" th:field="*{warmPrompt}" class="form-control" type="text"></textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-1 control-label">参考资料：</label>
                <div class="col-sm-11">
                    <textarea name="referenceMaterial" th:field="*{referenceMaterial}" class="form-control" type="text"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer"/>
    <th:block th:include="include :: datetimepicker-js"/>
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js"/>
    <th:block th:include="include :: jquery-smartwizard-js"/>
    <th:block th:include="include :: select2-js"/>
    <th:block th:include="include :: bootstrap-select-js"/>
    <th:block th:include="include :: summernote-js"/>
    <script src="/ueditor/ueditor.config.js" type="text/javascript" charSet="utf-8"></script>
    <script src="/ueditor/ueditor.all.js" type="text/javascript" charSet="utf-8"></script>
    <script src="/ueditor/lang/zh-cn/zh-cn.js" type="text/javascript" charSet="utf-8"></script>
    <script th:inline="javascript">
        var prefix = ctx + "ydz/japanNews";
        $("#form-japanNews-edit").validate({
            focusCleanup: true
        });

        //初始化加载
        $(document).ready(function () {
            parent.$('body').find('.layui-layer-max:not(.layui-layer-maxmin)').click()
        })

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-japanNews-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            if (val==""){
                $(".file-upload").fileinput({
                    uploadUrl: ctx + 'common/upload',
                    maxFileCount: 1,
                    autoReplace: true
                }).on('fileuploaded', function (event, data, previewId, index) {
                    $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName)
                }).on('fileremoved', function (event, id, index) {
                    $("input[name='" + event.currentTarget.id + "']").val('')
                })
            }else{
                $(this).fileinput({
                    'uploadUrl': ctx + 'common/upload',
                    initialPreviewAsData: true,
                    initialPreview: [val],
                    maxFileCount: 1,
                    autoReplace: true
                }).on('fileuploaded', function (event, data, previewId, index) {
                    $("input[name='" + event.currentTarget.id + "']").val(data.response.fileName)
                }).on('fileremoved', function (event, id, index) {
                    $("input[name='" + event.currentTarget.id + "']").val('')
                })
                $(this).fileinput('_initFileActions');
            }
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    dialogsInBody: true,
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>